#!/usr/bin/env python

# --------------------------------------
# projects/python/collatz/TestCollatz.py
# Copyright (C) 2009
# Glenn P. Downing
# --------------------------------------

# To run the tests
#     TestPrimes.py

# To document the tests
#     pydoc -w TestPrimes

import main
import unittest

# ----------
# TestReader
# ----------

class TestReader (object) :
    def __init__ (self, s) :
        self.s = s

    def read (self) :
        return self.s

# ----------
# TestWriter
# ----------

class TestWriter (object) :
    def str (self) :
        return self.s

    def write (self, *a) :
        self.s = str(a[0])
        for w in a[1:] :
            self.s += ' '
            self.s += str(w)
        self.s += '\n'

# -----------
# TestCollatz
# -----------

class TestPrimes (unittest.TestCase) :
    # ----
    # read
    # ----

    def test_read (self) :
        reader = TestReader('1\n')
        main.my_read(reader)
        self.assert_(main.i ==  1)

    # ----
    # eval
    # ----

    def test_eval1 (self) :
        main.i =  24
	main.one = 0
	main.two = 0
	main.three = 0
	main.four = 0
        main.my_eval()
        self.assert_(main.one == 2)
	self.assert_(main.two == 2)
	self.assert_(main.three == 3)
	self.assert_(main.four == 17)

    def test_eval2 (self) :
        main.i =  36
	main.one = 0
	main.two = 0
	main.three = 0
	main.four = 0
        main.my_eval()
        self.assert_(main.one == 2)
	self.assert_(main.two == 2)
	self.assert_(main.three == 3)
	self.assert_(main.four == 29)

    def test_eval3 (self) :
        main.i =  55
	main.one = 0
	main.two = 0
	main.three = 0
	main.four = 0
        main.my_eval()
        self.assert_(main.one == 2)
	self.assert_(main.two == 3)
	self.assert_(main.three == 3)
	self.assert_(main.four == 47)

    def test_eval4 (self) :
        main.i =  6790
	main.one = 0
	main.two = 0
	main.three = 0
	main.four = 0
        main.my_eval()
        self.assert_(main.one == 2)
	self.assert_(main.two == 2)
	self.assert_(main.three == 5)
	self.assert_(main.four == 6781)

    def test_eval5 (self) :
        main.i =  9999999
	main.one = 0
	main.two = 0
	main.three = 0
	main.four = 0
        main.my_eval()
        self.assert_(main.one == 2)
	self.assert_(main.two == 3)
	self.assert_(main.three == 3)
	self.assert_(main.four == 9999991)




    # -----
    # print
    # -----

    def test_print (self) :
        main.one =  1
        main.two = 2
        main.three = 3
        main.four = 4
        writer = TestWriter()
        main.my_print(writer)
        self.assert_(writer.str() == '1 2 3 4\n')

if __name__ == "__main__" :
    unittest.main()


